﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RRStorkRequest", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RRStorkRequest))]
    public class RRStorkRequestSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRRStorkRequest clazz;
        
        public RRStorkRequestSerializer(IRRStorkRequest clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("eIdentifier");
            if (clazz.EIdentifier!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EIdentifier))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : EIdentifier");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("PersonIdentifierMS");
            if (clazz.PersonIdentifierMS!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PersonIdentifierMS))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PersonIdentifierMS");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("PersonBirthday");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.PersonBirthday))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("PersonFirstname");
            if (clazz.PersonFirstname!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PersonFirstname))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PersonFirstname");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("PersonLastname");
            if (clazz.PersonLastname!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PersonLastname))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PersonLastname");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("LanguageOfCertificate");
            if (clazz.LanguageOfCertificate!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.LanguageOfCertificate))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : LanguageOfCertificate");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="eIdentifier") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStorkRequest>eIdentifier");
                }
                clazz.EIdentifier = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("eIdentifier")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStorkRequest>eIdentifier", Reader.LocalName);
            }
            if (Reader.LocalName=="PersonIdentifierMS") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStorkRequest>PersonIdentifierMS");
                }
                clazz.PersonIdentifierMS = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("PersonIdentifierMS")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStorkRequest>PersonIdentifierMS", Reader.LocalName);
            }
            if (Reader.LocalName=="PersonBirthday") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStorkRequest>PersonBirthday");
                }
                clazz.PersonBirthday = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("PersonBirthday")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStorkRequest>PersonBirthday", Reader.LocalName);
            }
            if (Reader.LocalName=="PersonFirstname") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStorkRequest>PersonFirstname");
                }
                clazz.PersonFirstname = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("PersonFirstname")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStorkRequest>PersonFirstname", Reader.LocalName);
            }
            if (Reader.LocalName=="PersonLastname") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStorkRequest>PersonLastname");
                }
                clazz.PersonLastname = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("PersonLastname")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStorkRequest>PersonLastname", Reader.LocalName);
            }
            if (Reader.LocalName=="LanguageOfCertificate") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRStorkRequest>LanguageOfCertificate");
                }
                clazz.LanguageOfCertificate = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("LanguageOfCertificate")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRStorkRequest>LanguageOfCertificate", Reader.LocalName);
            }
        }
    }
}
